#include "BaseInc.h"
#include "Progress.h"
#include "UIRender.h"
#include "Theme.h"
void Progress::SetMinValue(double minValue)
{
	min_ = minValue;
}

void Progress::SetMaxValue(double maxValue)
{
	max_ = maxValue;
}

void Progress::SetValue(double val)
{
	v_ = val;
}

double Progress::GetValue()
{
	return v_;
}

void Progress::Draw()
{
	Control::Draw();
	using namespace Theme;
	ITheme* theme = CustomTheme::GetInstance(); //Theme::GetDefaultTheme();

	float percent = v_ / (max_ - min_);

	UIRender::DrawFillRect(pos.x.val, pos.y.val, size.x.val, size.y.val, theme->GetBackColor());
	//UIRender::DrawString(glm::vec2(0, 0), text);
	if (bHorizen_)
		UIRender::DrawFillRect(pos.x.val, pos.y.val, size.x.val * percent, size.y.val, theme->GetForeColor());
	else
		UIRender::DrawFillRect(pos.x.val, pos.y.val, size.x.val, size.y.val * percent, theme->GetForeColor());

	//UIRender::DrawFillRect(pos.x, pos.y, size.x / 2, size.y, theme->GetBackColor());
	//UIRender::DrawString(glm::vec2(0, 0), text);
#ifdef _DEBUG
	UIRender::DrawString(vec2(pos.x.val,pos.y.val), L"progress");
#endif
	glLineWidth(2);
	UIRender::DrawEdgeRect(pos.x.val, pos.y.val, size.x.val, size.y.val, theme->GetBorderColor());

}

void Progress::SetHorizenDirection(bool bDir)
{
	bHorizen_ = bDir;
}

bool Progress::SetAttribute(const char* attrName, const char* attrVal)
{
	if (!Control::SetAttribute(attrName, attrVal))
	{
		if (strcmp(attrName, "max") == 0)
		{
			std::stringstream ss(attrVal);
			ss >> max_;
			return true;
		}
		else if (strcmp(attrName, "min") == 0)
		{
			std::stringstream ss(attrVal);
			ss >> min_;
			return true;
		}
		else if (strcmp(attrName, "value") == 0)
		{
			std::stringstream ss(attrVal);
			ss >> v_;
			return true;
		}
	}
	return false;
}

